<?php
namespace app\admin\logic;
use app\admin\code\BaseCode;
use app\admin\model\PicImgModel;
use app\admin\model\PicModel;
use app\admin\validate\BaseValidate;
use think\Lang;

class PicLogic  extends BaseLogic
{
    protected function _after_del_validate(){
        $model = new PicModel();
        if($model->deleteTrue(['id'=>$this->_param['id']])){
            $model->imgs()->where(['message_id'=>$this->_param['id']])->delete();
            $model->comment_num()->where(['message_id'=>$this->_param['id']])->delete();
            $model->like_num()->where(['message_id'=>$this->_param['id']])->delete();
            $this->result = true;
            return true;
        }else{
            $this->err = ['code'=>BaseCode::FAIL,'msg'=>Lang::get(BaseCode::FAIL)];
            $this->result = false;
            return false;
        }
    }
    public function update_status(BaseValidate $validate){
        if($validate->validate($this->_param,__FUNCTION__) === false){
            $this->result = false;
            $this->err = $validate->getError();
            return false;
        }else{
            $model = new PicModel();
            $model->save(['status'=>$this->_param['status']],['id'=>$this->_param['id']]);
            return true;
        }
    }
}


